package com.bugsnag.ohos;

import ohos.aafwk.ability.Ability;
import ohos.aafwk.ability.AbilityLifecycleCallbacks;
import ohos.utils.PacMap;

import com.bugsnag.ohos.util.OhosLog;

/**
 * SessionLifecycleCallback
 *
 * @since 2021-07-02
 */
public class SessionLifecycleCallback implements AbilityLifecycleCallbacks {
    private SessionTracker sessionTracker;

    /**
     * constructor
     *
     * @param sessionTracker
     */
    public SessionLifecycleCallback(SessionTracker sessionTracker) {
        this.sessionTracker = sessionTracker;
    }

    @Override
    public void onAbilityStart(Ability ability) {
        OhosLog.i("SessionLifecycleCallback", "onAbilityStart %s", ability);
        sessionTracker.onActivityStarted(ability.getClass().getSimpleName());
    }

    @Override
    public void onAbilityActive(Ability ability) {
        OhosLog.i("SessionLifecycleCallback", "onAbilityActive %s", ability);
    }

    @Override
    public void onAbilityInactive(Ability ability) {
        OhosLog.i("SessionLifecycleCallback", "onAbilityInactive %s", ability);
    }

    @Override
    public void onAbilityForeground(Ability ability) {
    }

    @Override
    public void onAbilityBackground(Ability ability) {
    }

    @Override
    public void onAbilityStop(Ability ability) {
        OhosLog.i("SessionLifecycleCallback", "onAbilityStop %s", ability);
        sessionTracker.onActivityStopped(ability.getClass().getSimpleName());
    }

    @Override
    public void onAbilitySaveState(PacMap pacMap) {
    }
}
